package com.zjw.zy.heart.control;

import com.zjw.zy.heart.bean.response.BaseResponse;
import com.zjw.zy.heart.bean.weather.WeatherDaysResult;
import com.zjw.zy.heart.bean.weather.WeatherHoursResult;
import com.zjw.zy.heart.service.IWeatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/weather")
public class WeatherControl {

    private IWeatherService weatherService;


    @GetMapping("/days")
    public BaseResponse<WeatherDaysResult> applyDaysWeather(@RequestParam("days") int days, @RequestParam("areaCode") int areaCode) {
        WeatherDaysResult dayWeather = weatherService.getDayWeather(days, areaCode);

        return BaseResponse.ofSuccess(dayWeather);
    }

    @GetMapping("/hours")
    public BaseResponse<WeatherHoursResult> applyHoursWeather(@RequestParam("hours") int hours, @RequestParam("areaCode") int areaCode) {
        WeatherHoursResult hourWeather = weatherService.getHourWeather(hours, areaCode);

        return BaseResponse.ofSuccess(hourWeather);
    }


    @Autowired
    public void setWeatherService(IWeatherService weatherService) {
        this.weatherService = weatherService;
    }
}
